package PlaneGame.CODE;

import java.awt.*;

import static PlaneGame.CODE.GameFrame.suspendFlag;

public abstract class GameObject implements Runnable{
    int changeRate=100;//刷新帧率
    boolean loop=true;
    boolean on_off=false;
    int x,y;

    public GameObject() {
        init();
    }
    void init(){
        off();
    }
    void on(){
        on_off=true;
    }
    void off(){
        on_off=false;
    }
    void shift(){
        on_off=!on_off;
    }
    final void drawMyself(Graphics g){//只有开关处于打开状态才显示,为防止重写，设置为final方法
        if(!on_off){
            return;
        }
        draw(g);
    }
    abstract void draw(Graphics g);

    @Override
    public void run() {//只有开关打开并且没暂停才变化
        while(loop){
            if (on_off&&!suspendFlag) {
                change();
            }
            try {
                Thread.sleep(changeRate);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
    abstract void change();
}
